import React from "react";
import {AppContext,DefaultContext} from "./context/index"
class MyButton extends React.Component{
    static contextType=DefaultContext;
    constructor(props){
        super(props)
        console.log("MyBotton 被调用了")
        this.state={
            title:"我是可以点击的"
        }
    }
    getContextFn(){
        console.log(this,)
        this.setState(state=>{
            return {title:"我被点击了"}
        })
        // console.log(this.app_context);
    }
    componentDidUpdate(){
        console.log("MyBotton 组件被更新了")
    }
    render(){
        return(
            <>
                <button  className="bg_409EFF pd_20 c_fff border_radius_4 mg_t_20" onClick={this.getContextFn.bind(this)}>{this.state.title}</button>
                <AppContext.Consumer>
                    {
                        item=>(
                            <DefaultContext.Consumer>
                                {
                                    value=>(
                                        <button item={item} date-value={value.value}  className="bg_409EFF pd_20 c_fff border_radius_4 mg_t_20" onClick={()=>value.change()}>我是可以点击的</button>
                                    )
                                }
                            </DefaultContext.Consumer>
                        )
                    }
                </AppContext.Consumer>
            </>
        )
    }
}
// MyButton.contextType =AppContext
export default MyButton